package com.viewhigh.wechat.sdk.bean;

import java.io.Serializable;

/**
 * @intro 封装 access_token
 * @author lengyu
 * @since 2016年3月29日 下午4:32:28
 */
public class AccessTokenCacheBean implements Serializable {

    private static final long serialVersionUID = -845566419962387043L;
    private String accessToken; // 正确获取到 access_token 时有值
    private Integer expiresIn; // 正确获取到 access_token 时有值默认为7200秒
    private Integer errcode; // 出错时有值
    private String errmsg; // 出错时有值
    private Long expiredTime; // 正确获取到 access_token 时有值，存放过期时间

    public String getAccessToken() {
        return accessToken;
    }


    public Integer getExpiresIn() {
        return expiresIn;
    }


    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }


    public void setExpiresIn(Integer expiresIn) {
        this.expiresIn = expiresIn;
    }


    public Integer getErrcode() {
        return errcode;
    }

    public void setErrcode(Integer errcode) {
        this.errcode = errcode;
    }

    public String getErrmsg() {
        return errmsg;
    }

    public void setErrmsg(String errmsg) {
        this.errmsg = errmsg;
    }

    public Long getExpiredTime() {
        return expiredTime;
    }

    public void setExpiredTime(Long expiredTime) {
        this.expiredTime = expiredTime;
    }

    /**
     * 校验是否可用
     * 
     * @return
     */
    public boolean isAvailable() {
        if (expiredTime == null)
            return false;
        if (errcode != null)
            return false;
        if (expiredTime < System.currentTimeMillis())
            return false;
        return accessToken != null;
    }
    
}